package com.danger.Model.action;

import android.content.Context;
import android.text.TextUtils;

import com.danger.Model.listener.OnVerifyListener;
import com.danger.Util.CheckMobileAndEmail;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.ResetPasswordByEmailListener;

/**
 * Created by danger on 2016/4/4.
 */
public class ForgetPasswordModelImpl implements ForgetPasswordModel {

    private Context context;
    private String EMAIL_IS_EMPTY = "邮箱为空";
    private String EMAIL_FORMAT_IS_WRONG = "邮箱格式不正确";
    private String IS_RIGHT = "正确";

    public ForgetPasswordModelImpl(Context context) {
        this.context = context;
    }

    @Override
    public void resetPassword(String email, final OnVerifyListener listener) {
        BmobUser.resetPasswordByEmail(context, email, new ResetPasswordByEmailListener() {
            @Override
            public void onSuccess() {
                listener.onSuccess();
            }

            @Override
            public void onFailure(int i, String s) {
                listener.onError("code = " + i + "," + "s = " + s);
            }
        });
    }

    @Override
    public String check(String email) {
        if (TextUtils.isEmpty(email)) {
            return EMAIL_IS_EMPTY;
        }
        if (!CheckMobileAndEmail.checkEmail(email)) {
            return EMAIL_FORMAT_IS_WRONG;
        }
        return IS_RIGHT;
    }
}
